﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Management.Automation;

using ESF.MUP.BasePlatform;
using ESF.MUP.BasePlatform.Domain.Model;
//using ESF.MUP.BasePlatform.DbService;
//using ESF.MUP.BasePlatform.DbService.MSSQL;


namespace ESF.MUP.Powershell
{
    /// <summary>
    /// Base cmdlet to use with MUP Management services
    /// </summary>
    public abstract class BaseCmdlet:Cmdlet
    {

        #region "Private members"
        private System.Diagnostics.Stopwatch _watch;
        #endregion

        /// <summary>
        /// start watch time and load interface configuration
        /// </summary>
        protected override void BeginProcessing()
        {
            WriteVerbose(String.Format("Start {0}", this.GetType().Name));
            _watch = new System.Diagnostics.Stopwatch();
            _watch.Start();
            base.BeginProcessing();
            //this.LoadConfiguration();
        }

        protected override void EndProcessing()
        {
            base.EndProcessing();
            _watch.Stop();
            WriteVerbose(String.Format("End {0} in {1}", this.GetType().Name, _watch.Elapsed));
        }

        private void LoadConfiguration()
        {
            string file=@"D:\Tools\MESF\Main\MiddlewareManager\ESF.MUP.Powershell\unity.config";
            //ESF.MUP.BasePlatform.MiddlewareManagementService.Current.LoadBaseConfiguration(file);

            #region "Helper to Unity configuration"
            //UnityContainer container = new UnityContainer();
            //container.RegisterType<System.Data.Common.DbConnection, System.Data.SqlClient.SqlConnection>(new InjectionConstructor(@"data source=.\ESF;initial catalog=CustomerRepository;integrated security=True"));


            //container.RegisterType<IUnitOfWork, SqlContext>();

            //IUnitOfWork ctx = container.Resolve<IUnitOfWork>();

            //container.RegisterType<IRepository<Application>, ApplicationRepository>(new InjectionConstructor(typeof(SqlContext)));

            //IRepository<Application> app = container.Resolve<IRepository<Application>>();

            //container.RegisterType<IApplicationService, ApplicationManagementService>(new InjectionConstructor(app));

            //IApplicationService appSvc2 = container.Resolve<IApplicationService>();
            #endregion
        }
    }
}
